package br.unifor.cct.mia.ga;

import java.awt.Color;
import java.util.HashMap;
import java.util.Map;

import weka.gui.explorer.ClassifierPanel;

import br.unifor.cct.mia.dataenhancement.Database;
import br.unifor.cct.mia.dataenhancement.Structure;
import br.unifor.cct.mia.evolutionary.SpeciesConstants;
import br.unifor.cct.mia.gui.Graphic;

public class GaFSW extends Ga {
	
	private static String[] configuracoes = {
		"br.unifor.cct.mia.xover.BasicXOver",
		"br.unifor.cct.mia.select.MinimizeRoulette",
		"br.unifor.cct.mia.evaluate.WekaFSWEvaluate",
		"br.unifor.cct.mia.mutation.MutationOriginal",
		"br.unifor.cct.mia.initialize.FixedSizeRandomInitialize"
	};

	private Integer specieType = new Integer(SpeciesConstants.FEATURE_SELECTION_FS);
	private Graphic graphic;	
	private Map genesAnt;
	private static int NVARS = 8;
	
	public GaFSW(Database dbOriginal, Structure structure, String[] options) {
		super(NVARS, configuracoes, options);
		System.out.println("[FSW]Numero de atributos -> "+structure.size());
		this.dbOriginal = dbOriginal;
    	this.structure = structure;
    	this.genesAnt = new HashMap();
		createGraphic();
	}
	
	protected void elitist() {
		//graphic.addPointLinha(1, generation, population[indexBestWorst[0]].getFitness());
		graphic.addPointLinha(2, generation, population[indexBestWorst[1]].getFitness());    	
		graphic.addPointLinha(3, generation, sum/configurations.getPopsize());    	
		super.elitist();
		graphic.addPointLinha(0, generation, population[configurations.getPopsize()].getFitness());    	
	}
	
	public Object[] getObjectsMutate() {
		Object[] o = new Object[1];
		o[0] = this;		
		return o;
	}
	
	public Object[] getObjectsSelect() {
		Object[] o = new Object[1];
		o[0] = this;
		return o;
	}
	
	public Object[] getObjectsEvaluate() {
		Object[] o = new Object[4];
		o[0] = structure;
		o[1] = genesAnt;
		o[2] = dbOriginal;
		o[3] = this;
		return o;
	}
	
	public Object[] getObjectsCrossover() {
		Object[] o = new Object[1];
		o[0] = this;
		return o;
	}
	
	public Object[] getObjectsInitialize() {
		Object[] o = new Object[2];
		o[0] = new Integer(structure.size()-1);
		o[1] = this;
		return o;
	}
	
	private void createGraphic() {
		graphic = new Graphic("Fitness Evaluation", "Generation", "Cost");
		
		graphic.createLine(0, "Best General Fitness");
		graphic.setColorLinha(0, Color.blue);
		
		graphic.createLine(1, "Best Population Fitness");
		graphic.setColorLinha(1, Color.green);
		
		graphic.createLine(2, "Worst Population Fitness");
		graphic.setColorLinha(2, Color.black);
		
		graphic.createLine(3, "Average Population Fitness");
		graphic.setColorLinha(3, Color.red);    	
	}        
	
	public Integer getSpecieType() {
		return specieType;
	}

	public void setSpecieType(Integer specieType) {
		this.specieType = specieType;
	}
}
